package com.yyk.yykywd.ui.work;

import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;
import android.widget.TextView;

import com.orhanobut.hawk.Hawk;
import com.orhanobut.logger.Logger;
import com.yyk.yykywd.R;
import com.yyk.yykywd.base.BaseActivity;
import com.yyk.yykywd.base.BaseRecyclerAdapter;
import com.yyk.yykywd.base.BaseRecyclerHolder;
import com.yyk.yykywd.http.ApiService;
import com.yyk.yykywd.bean.WorkPactdetailInfo;
import com.yyk.yykywd.util.Md5Util2;
import com.yyk.yykywd.widght.diver.more.SpacesItemDecoration;

import java.util.List;
import java.util.Map;
import java.util.TreeMap;

import butterknife.BindView;
import io.reactivex.Observer;
import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.disposables.Disposable;
import io.reactivex.schedulers.Schedulers;

/**
 * 查看合同列表
 */
public class QueryWorkPactActivity extends BaseActivity {


    @BindView(R.id.tv_number)
    TextView tvNumber;
    @BindView(R.id.tv_money)
    TextView tvMoney;
    @BindView(R.id.tv_createtime)
    TextView tvCreatetime;
    @BindView(R.id.rv_list)
    RecyclerView rvList;
    @BindView(R.id.tv_remark)
    TextView tvRemark;
    private String id;

    @Override
    public int getLayoutId() {
        return R.layout.activity_query_work_pact;
    }

    @Override
    public void initView() {
        setBackArrow();
        setTitle("合同列表");

    }

    @Override
    public void initData() {
        id = getBundle().getString("id");
        postWorkPactdetail(true);
    }


    /**
     * 接口20：查看合同 no（whm）
     */
    private void postWorkPactdetail(final boolean flag) {
        Map<String, String> map = new TreeMap<>();
        map.put("uid", Hawk.get("uid")+"");
        map.put("bid", id);

        map.put("sign", Md5Util2.createSign(map));
        ApiService.getInstance().api.postWorkPactdetail(map)
                .subscribeOn(Schedulers.io())     //调度线程
                .observeOn(AndroidSchedulers.mainThread())
                .unsubscribeOn(Schedulers.io())   //取消订阅
                .subscribe(new Observer<WorkPactdetailInfo>() {
                    @Override
                    public void onSubscribe(Disposable d) {

                    }

                    @Override
                    public void onNext(WorkPactdetailInfo info) {
                        Logger.e("查看合同" + info.toString());
                        if (info.getCode() == 1) {
                            String createtime = info.getData().getCreatetime();
                            tvCreatetime.setText(createtime);
                            String remark = info.getData().getRemark();
                            tvRemark.setText(remark);
                            tvMoney.setText(info.getData().getMoney() + "");
                            tvNumber.setText(info.getData().getNumber() + "");
                            List<String> img = info.getData().getImg();
                            BaseRecyclerAdapter<String> adapter3 = new BaseRecyclerAdapter<String>(mActivity, img, R.layout.adapter_item_shenqingimg_deteailb) {
                                @Override
                                public void convert(BaseRecyclerHolder holder, String item, int position, boolean isScrolling) {
                                    holder.setImageByUrl(R.id.iv_img, item);
                                }
                            };
                            rvList.setLayoutManager(new GridLayoutManager(mActivity, 4, GridLayoutManager.VERTICAL, false));
                            rvList.addItemDecoration(new SpacesItemDecoration(14, 0));
                            rvList.setAdapter(adapter3);


                        }
                    }

                    @Override
                    public void onError(Throwable e) {

                    }

                    @Override
                    public void onComplete() {

                    }
                });
    }

}
